import random

from matplotlib import pyplot as plt, font_manager

#设置字体(这样可以显示中文字体)
my_font = font_manager.FontProperties(fname='C:\Windows\Fonts\simsun.ttc', size=12)

x = range(120)
y = [random.randint(20, 35) for i in range(120)]

plt.figure(figsize=(20, 8), dpi=80)

# 调整x轴的刻度
# _x = list(x)[::10]
# _xtick_labels = ['hello,{}'.format(i) for i in _x]
# plt.xticks(_x, _xtick_labels)

_x = list(x)
_xtick_labels = ['10点{}分'.format(i) for i in range(60)]
_xtick_labels += ['11点{}分'.format(i) for i in range(60)]
#rotation是逆时针旋转角度
# plt.xticks(_x[::3], _xtick_labels[::3], rotation = 45, fontproperties = 'SimHei') #这样是可以的
plt.xticks(_x[::3], _xtick_labels[::3], rotation = 45, fontproperties = my_font)

plt.yticks(range(min(y), max(y) + 1))


#添加描述信息
plt.xlabel('时间', fontproperties = my_font)
plt.ylabel('温度 单位(℃)', fontproperties = my_font)
plt.title('10点到12点每分钟的气温变化情况', fontproperties = my_font)
#网格
#alpha是透明度，0最透明，1最明显
plt.grid(alpha = 0.3)


plt.plot(x, y)
plt.show()